<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">后台管理员</div>
                <div class="layui-card-body" pad15>


                    <div class="layui-form layui-form-pane" lay-filter="{$lay_table}">
                        <input type="hidden" name="id" value="{:array_get($info,'id')}">
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span style="color:#f90c05;">*</span>登录名</label>
                            <div class="layui-input-block">
                                <input type="text" name="admin_name" value="{:array_get($info,'admin_name')}" lay-verify="required"
                                       placeholder="请输入登录名"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span style="color:#f90c05;">*</span>登录密码</label>
                            <div class="layui-input-block">
                                <input type="text" name="password" value="" placeholder="请输入登录密码，不修改留空"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span style="color:#f90c05;">*</span>姓名</label>
                            <div class="layui-input-block">
                                <input type="text" name="realname" value="{:array_get($info,'realname')}" lay-verify="required"
                                       placeholder="请输入姓名"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">手机号</label>
                            <div class="layui-input-block">
                                <input type="text" name="mobile" value="{:array_get($info,'mobile')}" lay-verify="phone"
                                       placeholder="请输入号码" autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">备注</label>
                            <div class="layui-input-block">
                                <textarea name="remark" placeholder="请输入备注内容"
                                          class="layui-textarea">{:array_get($info,'remark')}</textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">角色</label>
                            <div class="layui-input-block">
                                <select lay-filter="adminrole" name="role">
                                    <option value="1" {:array_get($info,'role')===1 ?'selected' : '' }>超级管理员</option>
                                    <option value="2" {:array_get($info,'role')!==1 ?'selected' : '' }>普通管理员</option>
                                </select>
                                <div class="layui-form-mid layui-word-aux">超级管理员，默认具备所有权限，请谨慎设置。</div>
                            </div>
                        </div>
                        <div class="layui-form-item powerarrbox" style="display: {:array_get($info,'role')===1 ? 'none' : 'block' };"
                             pane>
                            <label class="layui-form-label">栏目权限</label>
                            <div class="layui-input-block" id="powerarr"></div>
                        </div>
                        <div class="layui-form-item" pane>
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-block">
                                <input type="checkbox" lay-filter="switch" name="status" {eq name="info.status|default=1" value="1" }checked{/eq} lay-skin="switch" lay-text="正常|禁用" value="1" />
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="button" lay-submit lay-filter="{$lay_btn}"
                                       value="确认提交" class="layui-btn">
                            </div>
                        </div>
                    </div>


                </div>
            </div>
        </div>
    </div>
</div>

<script>
    layui.use(['index', 'form', 'set', 'upload', 'tree'], function () {
        const $ = layui.$;
        const admin = layui.admin;
        const form = layui.form;
        const tree = layui.tree;
        form.render();

        form.on('select(adminrole)', function (data) {
            const val = data.value;
            if (val == 1) {
                $(".powerarrbox").css("display", "none");
            } else {
                $(".powerarrbox").css("display", "block");
            }
        });

        const defpowerarr = {$powerarr|raw|default= "[]"};
        tree.render({
            elem: '#powerarr',
            data: defpowerarr,
            showCheckbox: true,
            id: 'powerarr'
        });

        form.on('submit({$lay_btn})', function (obj) {
            const checkedData = tree.getChecked('powerarr');
            obj.field.powerids = getCheckedId(checkedData);

            const index = parent.layer.getFrameIndex(window.name);
            admin.req({
                url: "{:url('admin/editAdmin')}",
                data: obj.field,
                done: function (res) {
                    layer.msg("提交成功", {
                        icon: 1
                    });
                    parent.layui.table.reload('lay-admin-index-table'); //重载表格
                    parent.layer.close(index);
                }
            });
        });
    });
</script>
